package org.kojo.myket.dao;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

public abstract class AbstractDao<T> {
	private Class<T> entityClass;
	public AbstractDao(Class<T> entityClass){
		this.entityClass = entityClass;
	}
	protected abstract PersistenceManager getPersistenceManager();
	public void create(T entity){
		getPersistenceManager().makePersistent(entity);
	}
	public void edit(T entity){
		//undercronstruction
	}
	public void remove(T entity){
		getPersistenceManager().deletePersistent(entity);
	}
	public T find(Object id){
		return getPersistenceManager().getObjectById(entityClass,id);
	}
	public List<T> findAll(){
		Query q = getPersistenceManager().newQuery(entityClass);
		return (List<T>) q.execute();
	}
	public List<T> findRange(long start,long end){
		Query q = getPersistenceManager().newQuery(entityClass);
		q.setRange(start, end);
		return (List<T>) q.execute();
	}
	public int count(){
		return 0;
	}
}
